import {request} from "../../request/index.js"
import regeneratorRuntime from "../../lib/runtime/runtime"
Page({

    /**
     * 页面的初始数据
     */
    data: {
       leftLists:[],
       rightLists:[],
       //右侧内容滚动条距离顶部的距离
       scrollTop:0,
       //被点击的左侧菜单
       currentIndex:0
    },
    //接口返回数据
    Cates:[],

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
       
        this.getCates();
           
        
          
    },
    //获取分类数据
   async getCates(){
       
        const res  =await request({url:"/categories"});
        this.Cates=res;
        wx.setStorageSync('cates', {time:Date.now(),data:[this.Cates]});
        //  左侧
         let leftLists = this.Cates.map(v=>v.cat_name);
        //右侧
        let rightLists = this.Cates[0].children;
            this.setData({
                leftLists,
                rightLists
             })
    },
    onclick(e){
        const {index} = e.currentTarget.dataset;
        this.setData({
            currentIndex:index
        })
        let rightLists = this.Cates[index].children;
        this.setData({
            rightLists,
            scrollTop:0
        })
    }
  
})